import { Navigate, useLocation, useRoutes } from "react-router-dom";
import { RouteObject } from "@/routers/types/router";
// import Login from "@/pages/auth/Login";
// * 导入所有router
import "./style/transition.less";
const metaRouters = import.meta.glob("./modules/*.tsx", { eager: true });
const appRouters = import.meta.glob("./modules/apps/*.tsx", { eager: true });
// import DesignPortal from "@/designPortal";
import lazyLoad from "@/routers/components/LazyLoad";
import React from "react";
import { BaseLayoutIndex } from "./constants";

// * 处理路由
export const routerArray: RouteObject[] = [];

Object.keys(metaRouters).forEach(item => {
	// @ts-ignore
	Object.keys(metaRouters[item]).forEach((key: any) => {
		// @ts-ignore
		routerArray.push(...metaRouters[item][key]);
	});
});
Object.keys(appRouters).forEach(item => {
	// @ts-ignore
	Object.keys(appRouters[item]).forEach((key: any) => {
		// @ts-ignore
		routerArray.push(...appRouters[item][key]);
	});
});

export const rootRouter = [
	{
		path: "/",
		redirect: "/home"
	},
	{
		path: "/",
		element: <BaseLayoutIndex />,
		children: [
			{
				path: "home",
				component: () => import("@/pages/home"),
				meta: {
					requiresAuth: true,
					title: "首页",
					key: "home"
				}
			}
		]
	},
	{
		path: "/login",
		component: () => import("@/pages/auth/Login"),
		meta: {
			requiresAuth: false,
			title: "登录页",
			key: "login"
		}
	},
	{
		path: "/designPortal",
		component: () => import("@/designPortal"),
		meta: {
			requiresAuth: false,
			title: "可视化",
			key: "designPortal"
		}
	},
	{
		path: "/designReport",
		component: () => import("@/designReport"),
		meta: {
			requiresAuth: false,
			title: "可视化",
			key: "designReport"
		}
	},
	{
		path: "/404",
		component: () => import("@/pages/error/404"),
		meta: {
			requiresAuth: false,
			title: "404页面",
			key: "404"
		}
	},
	{
		path: "/403",
		component: () => import("@/pages/error/403"),
		meta: {
			requiresAuth: false,
			title: "403页面",
			key: "403"
		}
	},
	...routerArray,
	{
		path: "*",
		redirect: "/404"
	}
];

export default rootRouter;
